<?php
declare (strict_types = 1);
namespace app\course\logic\classes;

use app\common\exception\LogicException;
use app\course\model\classes\ClassesLink as ClassesLinkModel;

/**
 * 班级课程关联逻辑层
 * @method join(string $string, string $string1)
 * @method buildSql()
 */
class ClassesLink extends ClassesLinkModel
{

    /**
     * 获取班级课的课程目录
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date：   2020-08-04
     * @param  [type]                      $classes_id [description]
     * @return [type]                                  [description]
     */
    public function getCourseMenu($classes_id)
    {
    	return $this
			->field('course_id')
			->with(['course.coverUrl'])
			->where('classes_id', $classes_id)
			->select();
    }

    /**
     * 获取班级课的所有课程ID
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date：   2020-08-04
     * @param  [type]                      $classes_id [description]
     * @return [type]                                  [description]
     */
    public function getCourseIds($classes_id)
    {
    	return $this->where('classes_id', $classes_id)->column('course_id');
    }

    public function getCourseIdsByOneOfThem($course_id)
    {
        $classes_id = $this->where('course_id', $course_id)->value('classes_id');

        return $this->getCourseIds($classes_id);
    }

    public function getClassesIdsByCourseIds($course_ids)
    {
        $classes_ids = $this->where('course_id', 'IN', $course_ids)->column('classes_id');

        return $classes_ids;
    }

    public function getClassesNextCourseIdByCurr($classes_id, $course_id)
    {

        $next = $this->where('classes_id', $classes_id)->where('course_id', '>', $course_id)->value('course_id');

        return $next;
    }

    public function getClassesNextCourseByCurr($classes_id, $course_id)
    {

        $next = $this->where('classes_id', $classes_id)->where('course_id', '>', $course_id)->findOrEmpty();

        return $next;
    }
}
